/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Correo;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 *
 * @author estudiante
 */
public class MailSMTP extends Conexion {   

    public MailSMTP(String dom, int port, String orig) {
        dominio = dom;
        puerto = port;
        destino = "";
        origen = orig;
        subject = "";
        data = "";
    }

    public MailSMTP(String dom, int port, String dest, String orig, String subj, String data) {
        dominio = dom;
        puerto = port;
        destino = dest;
        origen = orig;
        subject = subj;
        this.data = data;
    }

    public boolean conectar() {
        try {
            this.socket = new Socket(dominio, this.puerto);
            out = new PrintWriter(this.socket.getOutputStream());
            in = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
            System.out.println("se ha establecido la conexion");
            return true;
        } catch (Exception e) {
            System.err.println("ERROR:AL CONECTAR");
            return false;
        }
    }

    public void EnviarMail() {
        try {
            System.out.println(enviarMensaje("EHLO " + dominio));
            //System.out.println(  enviarMensaje(Comandos.EHLO+"190.129.16.153"+"\n"));
            System.out.println(enviarMensaje("MAIL FROM:" + origen));
            System.out.println(enviarMensaje("RCPT TO:" + destino));
            System.out.println(enviarMensaje("DATA " + " \n"));
            System.out.println(enviarMensaje("Subject:" + subject + "\n\n" + data + "\n." + "\n" + "QUIT"));
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("ERROR:AL Enviar");
        }
    }
}
